<template>
  <div id="app-container">
    <header class="app-header">
      <h1>企业费用报销审批系统</h1>
      <div class="header-info">
        <span class="current-user">
          当前用户: <strong>{{ store.currentUser.name }}</strong>
          <span class="user-role">({{ roleLabel }})</span>
        </span>
      </div>
    </header>
    <main class="app-main">
      <router-view :key="store.currentUser.id" />
    </main>
  </div>
</template>

<script setup lang="ts">
import { computed, onMounted } from 'vue'
import { useApplicationStore } from '@/store/application'
import type { UserRole } from '@/services/models'

const store = useApplicationStore()

// 角色标签映射
const roleLabels: Record<UserRole, string> = {
  employee: '员工',
  head: '部门主管',
  finance: '财务',
  gm: '总经理',
}

// 当前用户角色标签
const roleLabel = computed(() => roleLabels[store.currentUser.role])

// 组件挂载时加载数据
onMounted(async () => {
  await store.fetchApplications()
  await store.fetchUserStats()
})
</script>

<style>
/* 全局样式 */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: #f4f6f9;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: #333;
}

#app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.app-header h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

.current-user {
  font-size: 14px;
}

.user-role {
  opacity: 0.8;
  font-size: 12px;
}

.app-main {
  flex: 1;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* 全局组件样式 */
h3 {
  color: #34495e;
  border-bottom: 2px solid #ecf0f1;
  padding-bottom: 10px;
  margin-top: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .app-header {
    padding: 15px 20px;
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }

  .app-header h1 {
    font-size: 20px;
  }

  .app-main {
    padding: 10px;
  }
}
</style>
